using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace eeZeeFTP
{
    public partial class Frm_eeZeeFTP : Form
    {
        private Cntrl_FTP ftp;
        private Cntrl_Download download;

        private ProgrammView CurrentView = ProgrammView.FTP;

        public Frm_eeZeeFTP()
        {
            InitializeComponent();

            //tP_Terminal.Controls.Add(new Cntrl_Putty());
            
            download = new Cntrl_Download(this);

            ftp = new Cntrl_FTP(download);

            this.Controls.Add(ftp);
            this.Controls.Add(download);

            ftp.BringToFront();

            Frm_eeZeeFTP_SizeChanged(this, EventArgs.Empty);

            cleanup();
        }

        private void cleanup()
        {
            string[] sFiles = System.IO.Directory.GetFiles(Parameter.TempPath);
            foreach (string sFile in sFiles)
            {
                try
                {
                    System.IO.File.Delete(sFile);
                }
                catch { }
            }
        }

        private void Frm_PrimaMeter_FormClosing(object sender, FormClosingEventArgs e)
        {
            cleanup();
        }

        private void btn_FTP_Click(object sender, EventArgs e)
        {
            switchView(ProgrammView.FTP);
        }

        private void btn_Download_Click(object sender, EventArgs e)
        {
            switchView(ProgrammView.Download);
        }

        public void switchView(ProgrammView view)
        {
            if (view == CurrentView) return;

            CurrentView = view;

            switch (view)
            {
                case ProgrammView.FTP:
                    ftp.Visible = true;
                    download.Visible = false;

                    btn_FTP.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_blue;
                    btn_Download.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_lightblue;

                    btn_FTP.ForeColor = Color.White;
                    btn_Download.ForeColor = Color.Black;

                    btn_Download.FlatAppearance.BorderColor = Color.FromArgb(80, 134, 201);
                    btn_FTP.FlatAppearance.BorderColor = Color.Orange;

                    ftp.BringToFront();
                    break;
                case ProgrammView.Download:
                    ftp.Visible = false;
                    download.Visible = true;

                    btn_FTP.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_lightblue;
                    btn_Download.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_blue;

                    btn_FTP.ForeColor = Color.Black;
                    btn_Download.ForeColor = Color.White;

                    btn_Download.FlatAppearance.BorderColor = Color.Orange;
                    btn_FTP.FlatAppearance.BorderColor = Color.FromArgb(80, 134, 201);

                    download.BringToFront();
                    break;
            }
        }

        private void Frm_eeZeeFTP_SizeChanged(object sender, EventArgs e)
        {
            if (this.WindowState != FormWindowState.Minimized)
            {
                int width = (this.Width - 6) / 2;
                btn_FTP.Width = width;
            }
        }

        private delegate void MyDelegateButton(Button myButton, string myArg);
        private void DelegateMethodButton(Button myButton, string myCaption)
        {
            myButton.Text = myCaption;
        }

        public void setDownLoadProgress(int iDownloadCount, int iProgress)
        {
            string sButtonText =  "Up-/Download";

            if(iDownloadCount > 0)
                sButtonText += " ( " + iDownloadCount + " Datei(en) - " + iProgress + " % )";

            if(this.Visible)
                BeginInvoke(new MyDelegateButton(DelegateMethodButton), new object[] { btn_Download, sButtonText });
        }

        private void btn_MouseEnter(object sender, EventArgs e)
        {
            Button b = (Button)sender;

            switch (b.Name)
            {
                case "btn_FTP":
                    switch(CurrentView)
                    {
                        case ProgrammView.FTP:
                            b.ForeColor = Color.Black;
                            b.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_lightblue;
                            break;
                        default:
                            b.ForeColor = Color.White;
                            b.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_blue;
                            break;
                    }
                    break;
                case "btn_Download":
                    switch(CurrentView)
                    {
                        case ProgrammView.Download:
                            b.ForeColor = Color.Black;
                            b.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_lightblue;
                            break;
                        default:
                            b.ForeColor = Color.White;
                            b.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_blue;
                            break;
                    }
                    break;
            } 
        }

        private void btn_MouseLeave(object sender, EventArgs e)
        {
            Button b = (Button)sender;

            switch (b.Name)
            {
                case "btn_FTP":
                    switch (CurrentView)
                    {
                        case ProgrammView.FTP:
                            b.ForeColor = Color.White;
                            b.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_blue;
                            break;
                        default:
                            b.ForeColor = Color.Black;
                            b.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_lightblue;
                            break;
                    }
                    break;
                case "btn_Download":
                    switch (CurrentView)
                    {
                        case ProgrammView.Download:
                            b.ForeColor = Color.White;
                            b.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_blue;
                            break;
                        default:
                            b.ForeColor = Color.Black;
                            b.BackgroundImage = eeZeeFTP.Properties.Resources.menubutton_lightblue;
                            break;
                    }
                    break;
            } 
        }
    }

    public enum ProgrammView
    {
        FTP = 0,
        Download = 1
    }
}